package io.zhifei.modules.sys.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.zhifei.common.utils.PageUtils;
import io.zhifei.common.utils.ToTree;
import io.zhifei.modules.sys.system.dao.MacDao;
import io.zhifei.modules.sys.system.dao.SysOrgDao;
import io.zhifei.modules.sys.system.entity.MacEntity;
import io.zhifei.modules.sys.system.entity.SysOrgEntity;
import io.zhifei.modules.sys.system.service.SysOrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SysOrgImpl extends ServiceImpl<SysOrgDao, SysOrgEntity> implements SysOrgService {

    @Autowired
    private SysOrgDao sysOrgDao;

    @Override
    public PageUtils getOrgList(Map<String, Object> params) {

        String keyWord = params.get("keyWord").toString();
        Integer page = Integer.valueOf(params.get("page").toString());
        Integer pageSize = Integer.valueOf(params.get("pageSize").toString());

        Page pageParams = new Page(page, pageSize);
        Page<Map<String, Object>> pageResult = sysOrgDao.getOrgList(pageParams, keyWord);
        return new PageUtils(pageResult);
    }

    @Override
    public Object addOrg(SysOrgEntity sysOrgEntity) {
        return sysOrgDao.addOrg(sysOrgEntity);
    }

    @Override
    public Object updateOrg(SysOrgEntity sysOrgEntity) {
        return sysOrgDao.updateOrg(sysOrgEntity);
    }

    @Override
    public Object deleteOrg(List<Long> orgIds) {
        for (Long id : orgIds) {
            SysOrgEntity sysOrgEntity = new SysOrgEntity();
            sysOrgEntity.setId(id);
            sysOrgEntity.setFlag(1);
            sysOrgDao.deleteById(sysOrgEntity);
        }
        return null;
    }

    @Override
    public Object orgTree() {
        //查询部门列表数据
        List<SysOrgEntity> orgEntities = sysOrgDao.getList();
        //将部门列表转为树形接口
//        ToTree.listToTree(orgEntities);
        return ToTree.listToTree(orgEntities);
    }

    @Override
    public Object orgList() {
        //查询部门列表数据
        List<SysOrgEntity> orgEntities = sysOrgDao.getList();
        return orgEntities;
    }

    @Override
    public List<SysOrgEntity> getList() {
        return sysOrgDao.getList();
    }


}
